Skip to content

[tooltip][preview-card] Deduplicate popup store open-change logic#5038

Draft
atomiks wants to merge 1 commit into
mui:masterfrom
atomiks:refactor/popup-store-and-handle-errors
Draft

[tooltip][preview-card] Deduplicate popup store open-change logic#5038
atomiks wants to merge 1 commit into
mui:masterfrom
atomiks:refactor/popup-store-and-handle-errors

Conversation

@atomiks

@atomiks atomiks commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

TooltipStore.setOpen and PreviewCardStore.setOpen were ~85% identical. This extracts the shared sequence — onOpenChange notification, cancellation, floating-root dispatch, reason → instantType mapping, setPopupOpenState, and the synchronous hover flushSync — into applyPopupOpenChange. Each store supplies only its differences via extraState (Tooltip's last change reason) and onBeforeDispatch (PreviewCard's inline-rect capture, guarded against a missing event). Behavior is preserved, and the duplicated runtime logic is removed from the bundle.

Verification

pnpm typescript, pnpm eslint, and the jsdom Tooltip / PreviewCard / popupStoreUtils suites all green.

@atomiks atomiks added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. component: tooltip Changes related to the tooltip component. component: preview card Changes related to the preview card component. component: menu Changes related to the menu component. component: popover Changes related to the popover component. labels Jun 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown

commit: c747e8f

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 12, 2026

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-256B(-0.06%) ▼-45B(-0.03%)

Details of bundle changes

Performance

Total duration: 1,311.00 ms -143.24 ms(-9.8%) | Renders: 50 (+0) | Paint: 1,986.56 ms -197.83 ms(-9.1%)

Test Duration Renders
Checkbox mount (500 instances) 84.55 ms ▼-29.54 ms(-25.9%) 1 (+0)

11 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@atomiks atomiks force-pushed the refactor/popup-store-and-handle-errors branch from 5156026 to 25df288 Compare June 12, 2026 08:20
@atomiks atomiks changed the title [popups] Deduplicate store setOpen and clarify handle errors [tooltip][preview-card] Deduplicate popup store open-change logic Jun 12, 2026
@atomiks atomiks removed component: menu Changes related to the menu component. component: popover Changes related to the popover component. labels Jun 12, 2026
@netlify

netlify Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit c747e8f
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a2bc9acb639bc0008343456
😎 Deploy Preview https://deploy-preview-5038--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR deduplicates the nearly identical setOpen logic in TooltipStore and PreviewCardStore by extracting the shared open-change sequence into a reusable applyPopupOpenChange helper in the popup store utilities.

Changes:

  • Added applyPopupOpenChange to centralize: onOpenChange notification + cancellation, floating-root dispatch, reasoninstantType mapping, setPopupOpenState, and hover flushSync.
  • Updated TooltipStore.setOpen and PreviewCardStore.setOpen to delegate to applyPopupOpenChange, passing store-specific differences via extraState and onBeforeDispatch.
  • Hardened PreviewCard hover inline-rect capture by guarding against a missing event.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/react/src/utils/popups/popupStoreUtils.ts Introduces shared applyPopupOpenChange helper and moves flushSync dependency into popup utilities.
packages/react/src/tooltip/store/TooltipStore.ts Replaces duplicated setOpen sequence with applyPopupOpenChange + tooltip-specific openChangeReason state.
packages/react/src/preview-card/store/PreviewCardStore.ts Replaces duplicated setOpen sequence with applyPopupOpenChange + preview-card inline-rect capture hook.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react/src/utils/popups/popupStoreUtils.ts Outdated
Comment thread packages/react/src/preview-card/store/PreviewCardStore.ts Outdated
Extract the shared `setOpen` sequence (reason classification, instantType
mapping, prevent-unmount handling, floating dispatch, synchronous hover flush)
into `applyPopupOpenChange`. TooltipStore and PreviewCardStore now supply only
their differences via `extraState` (last change reason) and `onBeforeDispatch`
(inline-rect capture, with a guard against a missing event).
@atomiks atomiks force-pushed the refactor/popup-store-and-handle-errors branch from 25df288 to c747e8f Compare June 12, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: preview card Changes related to the preview card component. component: tooltip Changes related to the tooltip component. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants